package org.Demo;

import java.util.Arrays;
import java.util.Scanner;

/*
* 判断101-200之间有多少个素数，并输出所有素数
* */
public class Demo4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入下限：");
        int floor = scanner.nextInt();
        System.out.println("请输入上限：");
        int upper  = scanner.nextInt();
        int result = searchPrime(floor,upper);
        System.out.println("素数的个数是："+result);
    }
    public static int searchPrime(int floor,int upper){
        int count = 0;
        for (int i = floor; i < upper; i++) {
            boolean flag = true;
            for (int j = 2; j <= Math.sqrt(i) ; j++) {
                if (i % j == 0) {
                    flag = false;
                    break;
                }
            }
            if(flag) {
                System.out.println(i);
                count++;
            }
        }
        return count;
    }
}
